﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _04_结构
{
    class Program
    {
        static void Main(string[] args)
        {
            //和类一样可以new
            StudentStruct s = new StudentStruct();
            s.Id = 11;
            s.Name = "James";
            s.Age = 12;
            Console.WriteLine("ID:{0},Name:{1},Age:{2}",s.Id,s.Name,s.Age);

            //和类一样可以初始化赋值
            StudentStruct s2 = new StudentStruct {Id=12,Name="Killy",Age=12 };
            Console.WriteLine("ID:{0},Name:{1},Age:{2}", s2.Id, s2.Name, s2.Age);

            //和类一样可以初始化赋值
            StudentStruct s3 = new StudentStruct(13, "Tim", 13);

            //结构必须要对所有结构内的字段初始化或者赋值
            StudentStruct s4;//没用new关键字，所以必须对结构内的所有字段初始化赋值
            s4.id = 14;//如果访问修饰符是private的话，就无法这样赋值，所以会报错
            s4.name = "Jom";
            s4.age = 14;
            
            Console.ReadKey();
        }
    }
    public struct StudentStruct
    {
        public int id;//这是字段，

        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        public string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public int age;

        public int Age
        {
            get { return age; }
            set { age = value; }
        }
        
       
        public string School;

        public StudentStruct(int id, string name, int age)
        {
            School = "beida";
            this.id = id;
            this.name = name;
            this.age = age;
        }
    }
}
